﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_City.cs
* 创建标识：曾乃强 15158756652 2011-04-19 09:04:41
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_City*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_City
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        /// <summary>
        /// 查看单个
        /// </summary>
        public Model.CNVP_City LoadByCode(string Code)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[Name],[ProvinceID] from " + Prefix + "City");
            sql.Append(" where [Code] = @Code");
            SqlParameter[] pra = {
                                 new SqlParameter("@Code",Code)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_City cnvp_city = new Model.CNVP_City();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_city.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                cnvp_city.Name = dr["Name"] is DBNull ? String.Empty : (string)dr["Name"];
                cnvp_city.ProvinceID = dr["ProvinceID"] is DBNull ? String.Empty : (string)dr["ProvinceID"];
            }
             return cnvp_city;
        }
        #endregion

        /// <summary>
        /// 查看全部,By ProvinceCode
        /// </summary>
        public List<Model.CNVP_City> LoadAll(string Code)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[Code],[Name] from " + Prefix + "City");
            sql.Append(" where [ProvinceID] = @ProvinceID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProvinceID",Code)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_City> list = new List<Model.CNVP_City>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_City cnvp_city = new Model.CNVP_City();
                    cnvp_city.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_city.Code = dr["Code"] is DBNull ? String.Empty : (string)dr["Code"];
                    cnvp_city.Name = dr["Name"] is DBNull ? String.Empty : (string)dr["Name"];
                    list.Add(cnvp_city);
                }
            }
            return list;

        }
    }
}

